int triggerPin = 2;
int echoPin = 3;

const int numOfReadings = 10;

int total = 0;
int averageDistance = 0;

unsigned long pulseTime;
unsigned long distance;

void setup() {
  pinMode(triggerPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  total = 0;
  
  for (int i=0; i<numOfReadings; i++) {
    digitalWrite(triggerPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(triggerPin, LOW);
    pulseTime = pulseIn(echoPin, HIGH);
    Serial.print("Pulse time: ");
    Serial.println(pulseTime);
    distance = pulseTime / 58;
    total += distance;
  }
  averageDistance = total / numOfReadings;
  Serial.print("Average Distance: ");
  Serial.println(averageDistance);
}

